package com.hetao.xx.fragment;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.hetao.xx.R;
import com.hetao.xx.adapter.PlaceAdapter;
import com.hetao.xx.game.model.NpcEvent;
import com.hetao.xx.game.model.Place;
import com.hetao.xx.orm.NpcEventVo;
import com.hetao.xx.service.PlaceEventService;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

public class HomeDialogFragment extends Fragment {

    private View root;
    private Unbinder unbinder;
    private NpcEventVo event;

    @SuppressLint("NonConstantResourceId")
    @BindView(R.id.dialog_title)
    TextView textView;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (root == null) {
            root = inflater.inflate(R.layout.fragment_home_dialog, container, false);
            unbinder = ButterKnife.bind(this, root);
            init();
        }
        return root;
    }

    public void init() {
        update();
    }

    public void update(){
        String message = this.event.message;
//        if(event.npc != null) {
//            message = String.format("%s: %s", event.npc.name, this.event.message);
//        }
        textView.setText(message);
    }

    public void setEvent(NpcEventVo event) {
        this.event = event;
    }

    @OnClick({R.id.home_dialog_ok, R.id.home_dialog_cancel})
    public void OnClick(View v) {
        switch (v.getId()) {
            case R.id.home_dialog_ok:

                break;
            case R.id.home_dialog_cancel:
                break;
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        update();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        //进行判空，避免空指针
        if (unbinder != null) {
            unbinder.unbind();
        }
    }
}
